var thismodel;
var startmodel=0;
var countmodel=5;
var currentpagemodel=1;
var ModelProxy = Objs("model.ModelProxy",
	Proxy,
{
	initialize: function( name,lists)
	{ 
		ModelProxy.$super.initialize.call( this, name,lists);
		thismodel=this;
	},	
	load:function()
	{
	var pagelimit=new Object();
		pagelimit.start=startmodel;
		pagelimit.count=countmodel;
		
		pagelimit.searchkey=$("#searchmodel").val();
		$.ajax({
				type: "POST",
				url:"../services/VehicleNameService.php?action=getAllModels",
				data:pagelimit,
				success: function(data,status) {
				var modeldata= eval('(' + data + ')');
				
				thismodel.sendNotification( NotificationNames.MODELDATA, modeldata );	
					
				},
				error:function(error,response){
				}
			});
	},
	save:function()
	{
		var modelobject=new Object();
		modelobject.makeID=$("#makecombo").val();
		modelobject.model=$("#model").val();
		modelobject.description=$("#modeldes").val();
		modelobject.created_by=global_user.admin_id;
		$('#modelpopup').modal('hide');
			$.ajax({
				type: "POST",
				url:"../services/VehicleNameService.php?action=addModel",
				data:modelobject,
				success: function(data,status) {
					//var makedata= eval('(' + data + ')');
					$('#progress').hide();
					thismodel.load();	
					$("#model").val('');	
					$("#modeldes").val('');
					bootbox.alert("Model Saved Successfully");
				},
				error:function(error,response){
				}
			});
	},
	updatemodel:function(modelObj)
	{
		$.ajax({
				type: "POST",
				url:"../services/VehicleNameService.php?action=editModel",
				data:modelObj,
				success: function(status) {

					//$("#searchmake").val('');
					$('#editModelPopup').modal('hide');
					$("#searchmodel").val('');
					thismodel.load();
					
					bootbox.alert("Update Success");
					
				},
				error:function(error,response){
				
					bootbox.alert("Edit Failed");
					
				}
			});
	},
	
	deleteModel:function(modelObj)
	{
		
		$.ajax({
				type: "POST",
				url:"../services/VehicleNameService.php?action=deleteModel",
				data:modelObj,
				success: function(modelObj,status) {
					//alert(status.result);
					bootbox.alert("Delete Success");
					$("#searchmodel").val('');
					thismodel.load();	
				},
				error:function(error,response){
				}
			});
	}
	
});
 